namespace Xmef.Engine.Internal
{
    using System;
    using System.Collections;
    using Xmef.Interfaces;
    using Xmef.Library;

    [Serializable]
    internal class PluginHostService : PluginIdentity, IPluginHostService, IPluginIdentity
    {
        private readonly Hashtable _hosts = new Hashtable();

        public IPluginHost Create(string hostName, string fileName, bool isDefault)
        {
            IPluginHostInternal _host = this._hosts[hostName] as IPluginHostInternal;
            if (_host == null)
            {
                _host = new PluginHost(hostName, fileName, isDefault);
                this._hosts[_host.HostName] = _host;
            }
            return _host;
        }

        public void Destroy(IPluginHost loaded)
        {
            IPluginHostInternal _host = this._hosts[loaded.HostName] as IPluginHostInternal;
            if (_host != null)
            {
                this._hosts.Remove(_host.HostName);
                _host.Clear();
            }
        }
    }
}

